package com.bop.dehong.category.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.base.dehong.base.AdapterBase;
import com.bop.dehong.R;
import com.bop.dehong.info.entity.RecommendProject;
import com.bop.dehong.widget.RoundProgressBar;

@SuppressLint("InflateParams")
public class CateListAdapter extends AdapterBase<RecommendProject> {

	public CateListAdapter(Activity context) {
		super(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.category_list_items, null);
			holder.product_type = getView(convertView, R.id.product_type);
			holder.iv = getView(convertView, R.id.category_list_items_iv);
			holder.tv_title = getView(convertView, R.id.category_list_items_title);
			holder.tv_rate = getView(convertView, R.id.category_list_items_rate);
			holder.tv_deadlines = getView(convertView, R.id.category_list_items_deadlines);
			holder.tv_sold = getView(convertView, R.id.category_list_items_money);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		RecommendProject entity = get(position);
		if (entity != null) {
			holder.tv_title.setText(entity.getTitle());
			holder.tv_rate.setText(entity.getRates());
			holder.tv_deadlines.setText(entity.getDeadlines());
			holder.tv_sold.setText(entity.getMoney());
			int producttype = Integer.valueOf(entity.getProduct());
			switch (producttype) {
			case 1:
				holder.product_type.setImageResource(R.mipmap.piaolebao);
				break;
			case 2:
				holder.product_type.setImageResource(R.mipmap.fangyitong);
				break;
			case 3:
				holder.product_type.setImageResource(R.mipmap.cheyitong);
				break;
			case 4:
				holder.product_type.setImageResource(R.mipmap.tiyanbao);
				break;
			case 5:
				holder.product_type.setImageResource(R.mipmap.xinyitong);
				break;
			}
			holder.iv.setProgress(entity.getPercent());
			int state = Integer.valueOf(entity.getState());
			switch (state) {
			case 1:
				holder.iv.setTitleName("招标中");
				break;
			case 5:
				holder.iv.setTitleName("已满标");
				break;
			case 7:
				holder.iv.setTitleName("还款中");
				break;
			case 9:
				holder.iv.setTitleName("已还清");
				break;
			case 12:
				holder.iv.setTitleName("预招标");
				break;
			default:
				break;
			}
		}
		return convertView;
	}

	private class ViewHolder {
		private ImageView product_type;
		private RoundProgressBar iv;
		private TextView tv_title;
		private TextView tv_rate;
		private TextView tv_deadlines;
		private TextView tv_sold;
	}
}
